/*
	Purpose: Do preliminary cleaning on the dta file for the 
	         "Americans View their Mental Health, 1957" dataset.
	Creates: import_cleaning_AVTMH1957.dta 
*/

clear
cd "$Mydirectory1/1_DataSources/Americans_MentalHealth_1957/"

use "./RawData/ICPSR03503.DTA" //Providing data in RawData folder because downloaded data must be converted from txt to dta

/*note: SSA study number is the same for all respondents (3503), 
        but interview number (V2) is UNIQUE, so V2 is the personal
        identification number. */ 

rename V* v*
keep v2 v4-v7 v10 v13 v14A v14B v14C v27-v36 v37A v37B v80 v92 v93 ///
     v95A v95B v138-v140 v143 v145 v177-v180 v181A v181B v181C v183A ///
     v183B v183C v190-v194 v195A v195B v293 v294 v299 v300 v304 v306 v309 ///
     v310 v314-v316 v320

/*------------------------------------------------------------------------------------------

									cleaning

------------------------------------------------------------------------------------------*/

label var v14A "CLUBS R BELONGS TO-MENTION 1"
label var v14B "CLUBS R BELONGS TO-MENTION 2"
label var v14C "CLUBS R BELONGS TO-MENTION 3"
label var v27 "HAPPIEST TIME OF R LIFE"
label var v28A "WHY PRESENT HAPPY TIME-MENTION 1"
label var v28B "WHY PRESENT HAPPY TIME-MENTION 2"
label var v28C "WHY PRESENT HAPPY TIME-MENTION 3"
label var v28D "WHY PRESENT HAPPY TIME-MENTION 4"
label var v29A "WHY R'S PAST WAS HAPPY-MENTION 1"
label var v29B "WHY R'S PAST WAS HAPPY-MENTION 2"
label var v29C "WHY R'S PAST WAS HAPPY-MENTION 3"
label var v30A "REASONS R PRESENTLY UNHAPPY (GENERAL)- MENTION 1"
label var v30B "REASONS R PRESENTLY UNHAPPY (GENERAL)- MENTION 2"
label var v30C "REASONS R PRESENTLY UNHAPPY (GENERAL)- MENTION 3"
label var v31A "REASONS R PRESENTLY UNHAPPY (DETAILED)- MENTION 1"
label var v31B "REASONS R PRESENTLY UNHAPPY (DETAILED)- MENTION 2"
label var v31C "REASONS R PRESENTLY UNHAPPY (DETAILED)- MENTION 3"
label var v33 "R'S AGE WHEN MOST UNHAPPY"
label var v34A "REAONS R WAS UNHAPPY AT THAT AGE-MENTION 1"
label var v34B "REAONS R WAS UNHAPPY AT THAT AGE-MENTION 2"
label var v34C "REAONS R WAS UNHAPPY AT THAT AGE-MENTION 3"
label var v35 "HOW HAPPY IS R PRESENTLY"
label var v36 "R XPCTS HAPPIER FUTURE?"
label var v37A "REASONS WHY R XPECTS TO BE HAPPIER IN FUTURE-MENTION 1"
label var v37B "REASONS WHY R XPECTS TO BE HAPPIER IN FUTURE-MENTION 2"
label var v80 "R'S MARITAL STATUS"
label var v92 "HOW HAPPY IS R'S CURRENT MARRIAGE"
label var v93 "WHETHER PAST UNHAPPINESS IN R'S MARRIAGE"
label var v95A "REASONS FOR PAST UNHAPPINESS IN R'S MARRIAGE-MENTION 1"
label var v95B "REASONS FOR PAST UNHAPPINESS IN R'S MARRIAGE-MENTION 2"
label var v138 "DOES R HAVE CHILDREN?"
label var v139 "# OF R'S LIVING MALE CHILDREN"
label var v140 "# OF R'S LIVING FEMALE CHILDREN"
label var v143 "AGE OF CHILDREN LIVING AT HOME"
label var v145 "# OF R'S DECEASED CHILDREN"
label var v177 "EMPLOYMENT STATUS OF R"
label var v178 "R'S OCCUPATION-MAJOR CATEGORIES"
label var v179 "R'S OCCUPATION-DETAILED"
label var v180 "R SATISFIED WITH JOB?"
label var v181A "GOOD ASPECTS OF R'S JOB-MENTION 1"
label var v181B "GOOD ASPECTS OF R'S JOB-MENTION 2"
label var v181C "GOOD ASPECTS OF R'S JOB-MENTION 3"
label var v183A "BAD ASPECTS OF R'S JOB-MENTION 1"
label var v183B "BAD ASPECTS OF R'S JOB-MENTION 2"
label var v183C "BAD ASPECTS OF R'S JOB-MENTION 3"
label var v190 "R SELF-EMPLOYED OR WORK FOR SOMEONE ELSE"
label var v191 "WHETHER R WOULD LIKE TO DO A DIFFERENT JOB"
label var v192 "WHAT KIND OF WORK WOULD R PREFER? (GENERAL)"
label var v193 "WHAT KIND OF WORK WOULD R PREFER? (DETAILED)"
label var v194 "KIND OF DISPARITY BTW CURRENT JOB AND PREFERRED JOB"
label var v195A "WHY R WOULD PREFER THIS OTHER KIND OF WORK-MENTION 1"
label var v195B "WHY R WOULD PREFER THIS OTHER KIND OF WORK-MENTION 2"
label var v293 "SEX OF R"
label var v306 "NATIONALITY-R'S PARENTS"
label var v309 "FATHER'S OCCUPATION WHEN R WAS A CHILD-MAJOR CATEGORIES"
label var v310 "FATHER'S OCCUPATION WHEN R WAS A CHILD-DETAILED"
label var v314 "WHETHER R LIVED WITH BOTH PARENTS UNTIL 16"
label var v315 "WHY R DIDN'T LIVE WITH BOTH PARENTS UNTIL 16"
label var v316 "WITH WHOM DID R LIVE UNTIL AGE 16 IF NOT BOTH PARENTS"
label var v320 "R's EXPECTED TOTAL FAMILY INCOME FOR THIS YEAR"
notes v320: "Total family income includes the income of R and immediate family memebers."


foreach var of varlist v27 v28A v28B v28C v28D v29A v29B v29C v31A v31B v31C v32 v34A v34B v34C v37A v37B v95A v95B v181A v181B v181C v183A v183B v183C v193 v194 v195A v195B v316 {
	replace `var' =. if inlist(`var',98,99,980,990) 
	summ `var'
}
	
foreach var of varlist v35 v36 v92 v93 v180 v191 v314 {
	tab `var', m
	replace `var' =. if inlist(`var',8,9) 
	tab `var', m
	summ `var'
} 

replace v10 =. if v10==9
replace v138 =. if v138==9
replace v139 =. if inlist(v139,60,70,99) 
replace v140 =. if inlist(v140,60,70,99) 
replace v143 =. if v143==99 //note: cannot replace 91 as "0" because otherwise it'll make it look like these Rs have preschool-aged children at home. Will leave as 91.
replace v145 =. if v145==9
replace v315 =. if v315==9
replace v320 =. if v320==99
tab v320, missing

save "./output/import_cleaning_AVTMH1957.dta", replace
